package com.android.plc.ui.control;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

import com.android.plc.CONST.COMMAND;
import com.android.plc.R;

public class SafeControl extends BaseControl implements OnClickListener
{
	private Button mLeaveBtn;
	private Button mHomeBtn;
	private Button mRestBtn;
	private Button mDisarmBtn;
	private Button mArmBtn;

	private static final int OFFSET_1 = 1;
	private static final int OFFSET_2 = 2;

	public static final int DATA = 0x64;

	public SafeControl(Context context, ViewGroup view, int res_id)
	{
		super(context, view, res_id);
	}

	public SafeControl(Context context, ViewGroup view)
	{
		super(context, view, R.layout.control_security);
	}

	@Override
	public void initView(ViewGroup view)
	{
		mLeaveBtn = (Button) view.findViewById(R.id.btn_leave_home);
		mHomeBtn = (Button) view.findViewById(R.id.btn_at_home);
		mRestBtn = (Button) view.findViewById(R.id.btn_rest);
		mDisarmBtn = (Button) view.findViewById(R.id.btn_disarm);
		mArmBtn = (Button) view.findViewById(R.id.btn_alarm);

		mLeaveBtn.setOnClickListener(this);
		mHomeBtn.setOnClickListener(this);
		mRestBtn.setOnClickListener(this);
		mDisarmBtn.setOnClickListener(this);
		mArmBtn.setOnClickListener(this);
	}

	public void onClick(View v)
	{
		switch (v.getId())
		{
		case R.id.btn_leave_home:
			sendCommand(OFFSET_1, COMMAND.ON, DATA, 0);
			break;
		case R.id.btn_at_home:
			sendCommand(OFFSET_1, COMMAND.OFF, 0, 0);
			break;
		case R.id.btn_rest:
			sendCommand(OFFSET_2, COMMAND.ON, DATA, 0);
			break;
		case R.id.btn_disarm:
			sendCommand(COMMAND.ON, DATA, 0);
			break;
		case R.id.btn_alarm:
			sendCommand(COMMAND.OFF, 0, 0);
			break;
		default:
			break;
		}
	}

	@Override
	public void onReceive(int command, int data1, int data2)
	{
	}

}
